
import './App.css';
import React, { useEffect } from 'react';
import {
  BrowserRouter,
  Route,
  Switch
} from 'react-router-dom'

import { Redirect } from 'react-router-dom/cjs/react-router-dom.min';
import Launch from './pages/Launch/launch';
import FingerprintJS from '@fingerprintjs/fingerprintjs'
import DeviceID from './utils/deviceId';
import Install from './pages/Install/install';

function App() {

  //初始化指纹
  useEffect(() => {

    window.addEventListener("onAppDidInstalled", (e) => {
      console.log("found: onAppDidInstalled");
    });

    if (!DeviceID.isValidVistorId()) {
      const fpPromise = FingerprintJS.load();
      fpPromise.then(fp => fp.get()).then(result => {
        DeviceID.saveVisitorId(result.visitorId);
        console.log("launch fingerprint: " + result.visitorId);
      });
    }
  }, [])

  return (
    <BrowserRouter basename="/h5onuacreditinstall">
      <div className="AppRoot">
        <div className="App">
          <Switch>
            <Route path='/launch' ><Launch /></Route>
            <Route path='/install' ><Install /></Route>

            <Redirect to='/launch'></Redirect>
          </Switch>
        </div>
      </div>
    </BrowserRouter>
  );
}

export default App;
